package nccloud.web.cmp.informer.informer.action;

import java.util.Collection;

import nc.md.persist.framework.IMDPersistenceQueryService;
import nc.vo.cmp.informer.InformerVO;
import nc.vo.ml.NCLangRes4VoTransl;
import nc.vo.pub.BusinessException;
import nccloud.dto.cmp.informer.vo.InformerLinkBillInfo;
import nccloud.dto.tmpub.bean.LinkInfor;
import nccloud.framework.core.exception.ExceptionUtils;
import nccloud.framework.core.json.IJson;
import nccloud.framework.service.ServiceLocator;
import nccloud.framework.web.action.itf.ICommonAction;
import nccloud.framework.web.container.IRequest;
import nccloud.framework.web.json.JsonFactory;
import nccloud.web.tmpub.pub.util.NCCLinkAppUtil;

public class InformerLinkBill implements ICommonAction {
	public Object doAction(IRequest request) {
		try {
			String read = request.read();
			IJson json = JsonFactory.create();
			InformerLinkBillInfo info = (InformerLinkBillInfo) json.fromJson(read, InformerLinkBillInfo.class);
			//add by ZTH
			
			String where = " pk_lower = '" + info.getPk() + "'";
			Collection<?> bills = null;
			bills = ((IMDPersistenceQueryService) ServiceLocator.find(IMDPersistenceQueryService.class))
					.queryBillOfVOByCond(InformerVO.class, where, true, false);
			InformerVO[] informervVO = (InformerVO[]) bills.toArray(new InformerVO[0]);
			String billtype=info.getBilltype();
			if(informervVO.length>0) {
				String subfamily=informervVO[0].getSubfamily();
				if("3642".equals(subfamily)) {
					billtype="3642";
				}
				
				
			}
			/*********************************/
			
			LinkInfor buildLinkInfor = NCCLinkAppUtil.buildLinkInfor(new String[]{info.getPk()}, billtype);
			if (buildLinkInfor.getUrl() != null && !buildLinkInfor.getUrl().equals("")) {
				buildLinkInfor.setUrl(buildLinkInfor.getUrl().substring(18));
				return buildLinkInfor;
			} else {
				throw new BusinessException(NCLangRes4VoTransl.getNCLangRes().getStrByID("3607nccloud_ncc_0",
						"03607nccloud_ncc-0247") + info.getBilltype()
						+ NCLangRes4VoTransl.getNCLangRes().getStrByID("3607nccloud_ncc_0", "03607nccloud_ncc-0248"));
			}
		} catch (BusinessException var6) {
			ExceptionUtils.wrapException(var6);
			return null;
		}
	}
}